home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10308 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: rand ?
  5. Date: 16 Mar 1996 10:31 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <16MAR199610311834@erich.triumf.ca>
  9. References: <4idjt4$4du@itsop2.its.brooklyn.cuny.edu>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4idjt4$4du@itsop2.its.brooklyn.cuny.edu>, dzielins@its.brooklyn.cuny.edu (Daniel Zielinski) writes...
  14. >I need to generate random numbers between 0 and 51, I tried rand() with srand(i)
  15. >i changes constantly but the program never exits. looks like the random number
  16. >is always the same.  any help would be apriciated... thanss
  17.  
  18. Since rand() and srand() are standard library functions that _do_ work when
  19. used as intended, a little sample of your use would be very helpful in
  20. diagnosing your problem.
  21.  
  22. srand() is normally called _once_ only.  Calling rand() reptetively will return
  23. a sequence of pseudo-random numbers between 0 and RAND_MAX (for MS-DOS, 0 to
  24. 32767).
  25.  
  26. The faq (available by ftp from rtfm.mit.edu) has some suggestions on getting
  27. random numbers in a specific range.
  28.  
  29.  
  30. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  31. Internet: bennett@triumf.ca         | of one another only when one can be
  32. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  33. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  34. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  35. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  36.  
  37.